<template>
	<!-- 活动详情 -->
	<view class="container">
		<!-- 头部导航 -->
		<page-navbar title="预约活动" backgroundColor="#87CEEB00" color="#fff" leftIconColor="#fff"></page-navbar>

		<!-- 主要内容区域 -->
		<scroll-view class="content" scroll-y="true" :show-scrollbar="false">
			<!-- 活动大图 -->
			<view class="image-section">
				<image class="main-image" :src="common.defaultImg(activityDetail.coverId)" mode="aspectFill"></image>
				<view class="image-overlay">
					<view class="activity-title">{{ activityDetail.title }}</view>
					<view class="activity-subtitle">{{ activityDetail.type?.name }}</view>
				</view>
			</view>

			<!-- 活动信息 -->
			<view class="section">
				<view class="section-header">
					<svg-icon name="info" size="32" />
					<text class="section-title">活动信息</text>
				</view>
				<view class="info-card">
					<view class="info-item">
						<view class="info-icon">
							<svg-icon name="calendar" size="36" />
						</view>
						<view class="info-content">
							<view class="info-label">活动时间</view>
							<view class="info-value">{{ activityDetail.startTime + ' - ' + activityDetail.endTime }}
							</view>
						</view>
					</view>
					<view class="info-item">
						<view class="info-icon">
							<svg-icon name="location" size="36" />
						</view>
						<view class="info-content">
							<view class="info-label">活动地点</view>
							<view class="info-value">{{ '活动地点' }}</view>
						</view>
					</view>
					<view class="info-item">
						<view class="info-icon">
							<svg-icon name="people" size="36" />
						</view>
						<view class="info-content">
							<view class="info-label">参与人数</view>
							<view class="info-value">{{ '限制20人/场次' }}</view>
						</view>
					</view>
				</view>
			</view>

			<view class="description-card">
				<rich-text class="rich-content" :nodes="activityDetail.intro"></rich-text>
			</view>

		</scroll-view>

		<!-- 底部预约按钮 -->
		<view class="bottom-action">
			<button class="reserve-btn" @click="handleReserve" v-if="type != 2">
				<text class="btn-text">立即预约</text>
				<view class="btn-icon">
					<svg-icon name="target" size="32" />
				</view>
			</button>

			<button class="reserve-btn" @click="getBack" v-else>
				<text class="btn-text">返回</text>
				<uni-icons type="undo" size="18" color="#fff"></uni-icons>
			</button>
		</view>
	</view>
</template>

<script setup>
import { ref, reactive, onMounted, watch, nextTick, computed } from 'vue';
import { onLoad, onShow, onPageScroll } from '@dcloudio/uni-app';
import { storeToRefs } from 'pinia';
import useSelectStore from '@/stores/select.js';
import useUserStore from '@/stores/user.js';
import dayjs from 'dayjs';
import api from "@/api"
import common from '@/utils/common.js'


const imgUrl = uni.imgUrl

// 状态管理
const selectStore = useSelectStore();
const userStore = useUserStore();
const { selectedVisitors } = storeToRefs(selectStore);
const { userInfo, isLogin } = storeToRefs(userStore);

// 活动详情数据
const activityDetail = ref({

});

const activity_id = ref(null)
const type = ref(null)

// 富文本内容
const richTextContent = ref(`<div style='line-height: 1.6; color: #333; background: #f8f9fa; padding: 20px;'><div style='margin-bottom: 30px;'><div style='display: flex; align-items: center; margin-bottom: 15px; gap: 12px;'><svg width="32" height="32" viewBox="0 0 24 24" style="opacity: 0.7;"><circle cx="12" cy="12" r="10" fill="#2196F3"/><path d="M11 7h2v2h-2zm0 4h2v6h-2z" fill="#FFF"/></svg><h3 style='font-size: 24px; font-weight: bold; color: #2E7D32; margin: 0;'>活动信息</h3></div><div style='background: rgba(255, 255, 255, 0.95); border-radius: 15px; padding: 25px; box-shadow: 0 3px 15px rgba(135, 206, 235, 0.1); border: 1px solid rgba(135, 206, 235, 0.1);'><div style='display: flex; align-items: flex-start; margin-bottom: 20px; gap: 15px;'><svg width="18" height="18" viewBox="0 0 24 24" style="margin-top: 3px; flex-shrink: 0;"><rect x="3" y="4" width="18" height="15" rx="2" fill="#2196F3"/><path d="M8 2v4M16 2v4" stroke="#1976D2" stroke-width="2"/><path d="M3 10h18" stroke="#FFF" stroke-width="1"/></svg><div style='flex: 1;'><div style='font-size: 14px; color: #666; margin-bottom: 4px;'>活动时间</div><div style='font-size: 16px; color: #333; font-weight: 500;'>每日 10:00-17:00</div></div></div><div style='display: flex; align-items: flex-start; margin-bottom: 20px; gap: 15px;'><svg width="18" height="18" viewBox="0 0 24 24" style="margin-top: 3px; flex-shrink: 0;"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7z" fill="#F44336"/><circle cx="12" cy="9" r="2.5" fill="#FFF"/></svg><div style='flex: 1;'><div style='font-size: 14px; color: #666; margin-bottom: 4px;'>活动地点</div><div style='font-size: 16px; color: #333; font-weight: 500;'>景区冒险岛区域</div></div></div><div style='display: flex; align-items: flex-start; gap: 15px;'><svg width="18" height="18" viewBox="0 0 24 24" style="margin-top: 3px; flex-shrink: 0;"><circle cx="9" cy="7" r="4" fill="#FF9800"/><path d="M9 14s-6 3-6 3v1h12v-1s-6-3-6-3"/><circle cx="18" cy="8" r="3" fill="#FF9800"/><path d="M18 13s-4 2-4 2v1h8v-1s-4-2-4-2"/></svg><div style='flex: 1;'><div style='font-size: 14px; color: #666; margin-bottom: 4px;'>参与人数</div><div style='font-size: 16px; color: #333; font-weight: 500;'>限制20人/场次</div></div></div></div></div><div style='margin-bottom: 30px;'><div style='display: flex; align-items: center; margin-bottom: 15px; gap: 12px;'><svg width="20" height="20" viewBox="0 0 24 24" style="opacity: 0.7;"><rect x="3" y="4" width="18" height="16" fill="#2196F3" rx="1"/><rect x="4" y="5" width="16" height="14" fill="#E3F2FD" rx="0.5"/><line x1="6" y1="8" x2="18" y2="8" stroke="#1976D2" stroke-width="0.5"/><line x1="6" y1="10" x2="16" y2="10" stroke="#1976D2" stroke-width="0.5"/></svg><h3 style='font-size: 24px; font-weight: bold; color: #2E7D32; margin: 0;'>活动介绍</h3></div><div style='background: rgba(255, 255, 255, 0.95); border-radius: 15px; padding: 25px; box-shadow: 0 3px 15px rgba(135, 206, 235, 0.1); border: 1px solid rgba(135, 206, 235, 0.1);'><div style='font-size: 18px; line-height: 1.6; color: #333;'><p style='margin-bottom: 15px;'><strong>🏴‍☠️ 活动概述</strong></p><p style='margin-bottom: 15px;'>加勒比海盗沉浸宝藏是一场集探险、解谜、团队协作于一体的主题活动。参与者将化身为勇敢的海盗，在神秘的加勒比海域寻找传说中的宝藏。</p><p style='margin-bottom: 15px;'><strong>🗺️ 活动流程</strong></p><p style='margin-bottom: 10px;'>1. <strong>集合准备</strong>：在海盗船长的带领下，了解寻宝任务和规则</p><p style='margin-bottom: 10px;'>2. <strong>装备发放</strong>：每位参与者将获得海盗帽、寻宝地图、指南针等道具</p><p style='margin-bottom: 10px;'>3. <strong>探险寻宝</strong>：根据线索在各个关卡中解谜，寻找宝藏碎片</p><p style='margin-bottom: 10px;'>4. <strong>最终挑战</strong>：集齐所有碎片，开启神秘宝箱</p><p style='margin-bottom: 15px;'>5. <strong>庆祝仪式</strong>：获得珍贵的海盗勋章和纪念品</p><p style='margin-bottom: 15px;'><strong><svg width="16" height="16" viewBox="0 0 24 24" style="display: inline; vertical-align: middle; margin-right: 8px;"><ellipse cx="12" cy="12" rx="8" ry="9" fill="#FFE082"/><ellipse cx="9" cy="10" rx="1.5" ry="2" fill="#333"/><ellipse cx="15" cy="10" rx="1.5" ry="2" fill="#333"/><path d="M8 15 Q12 18 16 15" fill="none" stroke="#333" stroke-width="2"/></svg>沉浸体验</strong></p><p style='margin-bottom: 15px;'>活动采用全沉浸式设计，专业演员扮演海盗船长和神秘商人，为参与者营造真实的海盗世界氛围。现场还有精心布置的海盗船、神秘洞穴等场景。</p><p style='margin-bottom: 15px;'><strong><svg width="16" height="16" viewBox="0 0 24 24" style="display: inline; vertical-align: middle; margin-right: 8px;"><path d="M7 4v6c0 3.31 2.69 6 6 6s6-2.69 6-6V4H7z" fill="#FFD700"/><path d="M5 8h2v4c0 1.1-.9 2-2 2s-2-.9-2-2v-2c0-1.1.9-2 2-2z" fill="#FFA000"/><path d="M19 8h-2v4c0 1.1.9 2 2 2s2-.9 2-2v-2c0-1.1-.9-2-2-2z" fill="#FFA000"/></svg>奖励机制</strong></p><p style='margin-bottom: 10px;'>• 完成任务的参与者将获得限量版海盗勋章</p><p style='margin-bottom: 10px;'>• 表现优秀的团队可获得神秘宝箱和丰厚奖品</p><p style='margin-bottom: 15px;'>• 所有参与者都能获得精美的活动纪念品</p></div></div></div><div style='margin-bottom: 30px;'><div style='display: flex; align-items: center; margin-bottom: 15px; gap: 12px;'><svg width="20" height="20" viewBox="0 0 24 24" style="opacity: 0.7;"><path d="M1 21h22L12 2 1 21z" fill="#FF9800"/><path d="M12 18h.01M12 15V9" stroke="#FFF" stroke-width="2"/></svg><h3 style='font-size: 24px; font-weight: bold; color: #2E7D32; margin: 0;'>注意事项</h3></div><div style='background: rgba(255, 255, 255, 0.95); border-radius: 15px; padding: 25px; box-shadow: 0 3px 15px rgba(135, 206, 235, 0.1); border: 1px solid rgba(135, 206, 235, 0.1);'><div style='display: flex; align-items: flex-start; margin-bottom: 12px; gap: 12px;'><span style='color: #FF6B35; font-weight: bold; font-size: 18px; flex-shrink: 0; margin-top: 2px;'>•</span><span style='font-size: 16px; color: #333; line-height: 1.5; flex: 1;'>活动需提前预约筹备，现场临时报名可能导致无法参与</span></div><div style='display: flex; align-items: flex-start; margin-bottom: 12px; gap: 12px;'><span style='color: #FF6B35; font-weight: bold; font-size: 18px; flex-shrink: 0; margin-top: 2px;'>•</span><span style='font-size: 16px; color: #333; line-height: 1.5; flex: 1;'>建议穿着舒适的运动鞋，避免穿高跟鞋</span></div><div style='display: flex; align-items: flex-start; margin-bottom: 12px; gap: 12px;'><span style='color: #FF6B35; font-weight: bold; font-size: 18px; flex-shrink: 0; margin-top: 2px;'>•</span><span style='font-size: 16px; color: #333; line-height: 1.5; flex: 1;'>活动过程中请听从工作人员指挥，注意安全</span></div><div style='display: flex; align-items: flex-start; margin-bottom: 12px; gap: 12px;'><span style='color: #FF6B35; font-weight: bold; font-size: 18px; flex-shrink: 0; margin-top: 2px;'>•</span><span style='font-size: 16px; color: #333; line-height: 1.5; flex: 1;'>雨天活动可能会调整或取消，请关注天气预报</span></div><div style='display: flex; align-items: flex-start; margin-bottom: 12px; gap: 12px;'><span style='color: #FF6B35; font-weight: bold; font-size: 18px; flex-shrink: 0; margin-top: 2px;'>•</span><span style='font-size: 16px; color: #333; line-height: 1.5; flex: 1;'>儿童参与需有成人陪同，12岁以下儿童享受优惠价格</span></div><div style='display: flex; align-items: flex-start; margin-bottom: 12px; gap: 12px;'><span style='color: #FF6B35; font-weight: bold; font-size: 18px; flex-shrink: 0; margin-top: 2px;'>•</span><span style='font-size: 16px; color: #333; line-height: 1.5; flex: 1;'>活动现场禁止携带危险物品，请配合安检</span></div><div style='display: flex; align-items: flex-start; gap: 12px;'><span style='color: #FF6B35; font-weight: bold; font-size: 18px; flex-shrink: 0; margin-top: 2px;'>•</span><span style='font-size: 16px; color: #333; line-height: 1.5; flex: 1;'>预约成功后请提前15分钟到达集合地点</span></div></div></div></div>`)

onLoad((query) => {
	if (query.id) {
		activity_id.value = query.id
		getData();
	}
	if (query.type) {
		type.value = query.type
	}
});

onMounted(() => {

});

const getBack = () => {
	uni.navigateBack()
}

const getData = () => {
	api.attractionsApi.detailInfo({ id: activity_id.value }).then(res => {
		console.log('加载活动数据', res);
		activityDetail.value = res
	})
};

// 立即预约
const handleReserve = () => {
	if (!isLogin.value) {
		uni.showToast({
			title: '您还未登录，请先登录',
			icon: 'error'
		})
		setTimeout(() => {
			uni.navigateTo({
				url: '/pages/user'
			})
		}, 1000)
		return
	}
	// 初始化状态机中的数据
	selectedVisitors.value = [];
	// 跳转预约活动页面
	uni.navigateTo({
		url: '/pages/details/activityReservation?id=' + activityDetail.value.id
	})
};
</script>

<style lang="scss" scoped>
.container {
	background: linear-gradient(180deg, #87CEEB 0%, #F0F8FF 50%, #ffffff 100%);
	height: 100vh;
	width: 100%;
	position: relative;
	overflow: hidden;
	box-sizing: border-box;
	display: flex;
	flex-direction: column;
	padding-bottom: 120rpx;
}

.content {
	flex: 1;
	overflow: hidden;
	box-sizing: border-box;
	position: relative;
	z-index: 1;
	padding-top: 24rpx;
}

/* 图片区域 */
.image-section {
	position: relative;
	height: 500rpx;
	margin: 0 30rpx 30rpx 30rpx;
	border-radius: 20rpx;
	overflow: hidden;

	.main-image {
		width: 100%;
		height: 100%;
	}

	.image-overlay {
		position: absolute;
		bottom: 0;
		left: 0;
		right: 0;
		background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
		padding: 40rpx 30rpx 30rpx;
		color: white;

		.activity-title {
			font-size: 36rpx;
			font-weight: bold;
			margin-bottom: 10rpx;
		}

		.activity-subtitle {
			font-size: 26rpx;
			opacity: 0.9;
		}
	}
}

.section {
	margin: 0 30rpx 40rpx 30rpx;

	.section-header {
		display: flex;
		align-items: center;
		margin-bottom: 20rpx;
		padding: 0 10rpx;
		gap: 20rpx;

		.section-title {
			font-size: 32rpx;
			font-weight: bold;
			color: #2E7D32;
		}

		.section-decoration {
			font-size: 28rpx;
			opacity: 0.7;
		}
	}
}

/* 信息卡片 */
.info-card {
	background: rgba(255, 255, 255, 0.95);
	border-radius: 20rpx;
	padding: 30rpx;
	box-shadow: 0 4rpx 20rpx rgba(135, 206, 235, 0.1);

	.info-item {
		display: flex;
		align-items: flex-start;
		margin-bottom: 25rpx;
		gap: 20rpx;

		&:last-child {
			margin-bottom: 0;
		}

		.info-icon {
			width: 36rpx;
			height: 36rpx;
			margin-top: 4rpx;
			flex-shrink: 0;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.info-content {
			flex: 1;

			.info-label {
				font-size: 24rpx;
				color: #666;
				margin-bottom: 5rpx;
			}

			.info-value {
				font-size: 26rpx;
				color: #333;
				font-weight: 500;
			}
		}
	}
}

/* 描述卡片 */
.description-card {
	background: rgba(255, 255, 255, 0.95);
	border-radius: 20rpx;
	padding: 24rpx;
	box-shadow: 0 4rpx 20rpx rgba(135, 206, 235, 0.1);

	.rich-content {
		font-size: 28rpx;
		line-height: 1.6;
		color: #333;
	}
}


/* 注意事项卡片 */
.notice-card {
	background: rgba(255, 255, 255, 0.95);
	border-radius: 20rpx;
	padding: 30rpx;
	box-shadow: 0 4rpx 20rpx rgba(135, 206, 235, 0.1);

	.notice-item {
		display: flex;
		align-items: flex-start;
		margin-bottom: 15rpx;
		gap: 15rpx;

		&:last-child {
			margin-bottom: 0;
		}

		.notice-bullet {
			color: #FF6B35;
			font-weight: bold;
			font-size: 28rpx;
			flex-shrink: 0;
			margin-top: 2rpx;
		}

		.notice-text {
			font-size: 26rpx;
			color: #333;
			line-height: 1.5;
			flex: 1;
		}
	}
}


/* 底部预约按钮 */
.bottom-action {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	background: rgba(255, 255, 255, 0.95);
	backdrop-filter: blur(10rpx);
	padding: 20rpx 30rpx;
	padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
	border-top: 1rpx solid rgba(135, 206, 235, 0.2);
	z-index: 100;
	width: 100%;
	box-sizing: border-box;

	.reserve-btn {
		width: 100%;
		height: 80rpx;
		background: linear-gradient(135deg, #4CAF50, #66BB6A);
		border-radius: 40rpx;
		border: none;
		display: flex;
		align-items: center;
		justify-content: center;
		gap: 15rpx;
		box-shadow: 0 8rpx 24rpx rgba(76, 175, 80, 0.3);
		transition: all 0.3s ease;

		&:active {
			transform: scale(0.98);
			box-shadow: 0 4rpx 12rpx rgba(76, 175, 80, 0.4);
		}

		.btn-text {
			font-size: 32rpx;
			font-weight: bold;
			color: white;
		}

		.btn-icon {
			width: 32rpx;
			height: 32rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
}
</style>
